package com.tangzx.builder.context;

import java.util.HashMap;

import com.tangzx.builder.IMixWordFactory;
import com.tangzx.builder.abc.string.AbcString;
/**
 * @author Administrator
 *
 */
public class AbcContext implements IAbcContext {

	private HashMap<String, AbcString> stringPool = new HashMap<String, AbcString>();
	private IMixWordFactory mixWordFactory;
	
	public AbcString getString(String str) {
		AbcString as = stringPool.get(str);
		if (as == null) {
			as = AbcString.get(str);
			stringPool.put(str, as);
		}
		return as;
	}

	public HashMap<String, AbcString> getAllString() {
		return stringPool;
	}

	public void merge(IAbcContext target) {
		stringPool.putAll(target.getAllString());
	}

	public IAbcContext cloneContext() {
		IAbcContext clone = new AbcContext();
		clone.merge(this);
		return clone;
	}
	
	public String makeWord(String st) {
		String s = mixWordFactory.makeWord(st);
		return s;
	}

	public IMixWordFactory getMixWordFactory() {
		return mixWordFactory;
	}

	public void setMixWordFactory(IMixWordFactory mixWordFactory) {
		this.mixWordFactory = mixWordFactory;
	}

	private HashMap<String, String> class2package = new HashMap<String, String>();
	
	public void registerClassName(AbcString packageAS, AbcString classAS) {
		class2package.put(classAS.vo.getOriValue(), packageAS.vo.getOriValue());
	}

	public boolean hasSameClassNameButNotSamePackage(AbcString packageAS,
			AbcString classAS) {
		String targetPackage = class2package.get(classAS.vo.getOriValue());
		Boolean notSame = targetPackage != null && !packageAS.vo.getOriValue().equals(targetPackage);
		//if (notSame)
		//	System.out.println("--------------\n" + classAS.vo.getOriValue() + "\n" + targetPackage + "\n" + packageAS.vo.getOriValue());
		return notSame;
	}
}
